home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
398
/
398.xpi
/
chrome
/
forecastfox.jar
/
content
/
icons
/
icons.js
< prev
next >
Wrap
Text File
|
2010-02-04
|
6KB
|
171 lines
/*------------------------------------------------------------------------------
Copyright (c) 2008 Ensolis, LLC. All Rights Reserved.
----------------------------------------------------------------------------*/
var gIcons = null;
function iconsLoad()
{
gIcons = new Icons();
gIcons.start();
}
function iconsUnload()
{
gIcons.stop();
gIcons = null;
}
function Icons() {}
Icons.prototype = {
_bundle: null,
_manager: null,
_name: null,
_url: null,
_progress: null,
_description: null,
_install: null,
_persist: null,
_file: null,
_cancel: null,
start: function Icons_start()
{
//setup components
this._bundle = document.getElementById("ff-bundle-icons");
this._manager = Components.classes["@ensolis.com/forecastfox/manager-service;1"].getService(Components.interfaces.ffIManagerService);
//set display
this._name = document.getElementById("ff-icons-name");
this._url = document.getElementById("ff-icons-url");
this._progress = document.getElementById("ff-icons-progress");
this._description = document.getElementById("ff-icons-description");
this._install = document.getElementById("ff-button-install");
this._cancel = document.getElementById("ff-button-cancel");
var params = window.arguments[0].QueryInterface(
Components.interfaces.nsIDialogParamBlock);
this._name.value = params.GetString(0);
this._url.value = params.GetString(1);
this._url.tooltiptext = this._url.value;
},
stop: function Icons_stop()
{
//stop download or install
try {
if (this._persist && this._persist.currentState < 3)
this._persist.cancelSave();
if (this._file && this._file.exists())
this._file.remove(false);
} catch(e) {}
//remove variables
this._url = null;
this._name = null;
this._manager = null;
this._bundle = null;
this._progress = null;
this._description = null;
this._install = null;
this._persist = null;
this._file = null;
this._cancel = null;
},
install: function Icons_install()
{
//set display
this._install.setAttribute("disabled", "true");
this._progress.removeAttribute("collapsed");
this._progress.setAttribute("value", "0");
this._progress.setAttribute("mode", "determined");
this._description.value = this._bundle.getString("ff.icons.download");
window.sizeToContent();
//convert url to uri and get file
var ios = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
var uri = ios.newURI(this._url.value, null, null);
var fileName = uri.QueryInterface(Components.interfaces.nsIURL).fileName;
this._file = this._manager.disk.get(fileName, Components.interfaces.ffIDiskService.TYPE_TEMP);
//persist the file
var flags = 0x02 | 0x32;
this._persist = Components.classes["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"].createInstance(Components.interfaces.nsIWebBrowserPersist);
this._persist.persistFlags |= flags;
this._persist.progressListener = this;
this._persist.saveURI(uri, null, null, null, null, this._file);
},
_installItem: function Icons__installItem()
{
//perform install
try {
var rv = this._manager.icons.setItem(this._file);
} catch(e) {
this._description.value = this._bundle.getString("ff.icons.failed");
this._manager.disk.log("Failed to install icon pack.", e, null);
}
//set progress
this._progress.setAttribute("value", "100");
this._progress.setAttribute("mode", "determined");
this._cancel.label = this._bundle.getString("ff.icons.close");
//set description
if (rv) {
this._description.value = this._bundle.getString("ff.icons.success");
window.setTimeout(window.close, 0);
} else
this._description.value = this._bundle.getString("ff.icons.failed");
//remove persisted file
try {
this._file.remove(false);
} catch(e) {}
},
///////////////////////////
// nsIWebProgressListener
onLocationChange: function Icons_onLocationChange(webProgress, request, location) {},
onSecurityChange: function Icons_onSecurityChange(webProgress, request, state) {},
onStatusChange: function Icons_onStatusChange(webProgress, request, status, message) {},
onProgressChange: function Icons_onProgressChange(webProgress, request, curSelfProgress, maxSelfProgress, curTotalProgress, maxTotalProgress )
{
if (maxTotalProgress > 0) {
var percentage = (curTotalProgress * 100) / maxTotalProgress;
this._progress.value = percentage;
}
},
onStateChange: function Icons_onStateChange(webProgress, request, stateFlags, status)
{
var stateDone = Components.interfaces.nsIWebProgressListener.STATE_STOP;
//download complete
if (stateDone == (stateFlags & stateDone)) {
var comp = this;
var channel = request.QueryInterface(Components.interfaces.nsIHttpChannel);
if (channel.responseStatus == 200) {
this._progress.removeAttribute("value");
this._progress.setAttribute("mode", "undetermined");
this._description.value = this._bundle.getString("ff.icons.install");
window.setTimeout(function() { comp._installItem(); }, 0);
} else {
this._progress.setAttribute("value", "100");
this._progress.setAttribute("mode", "determined");
this._cancel.label = this._bundle.getString("ff.icons.close");
this._description.value = this._bundle.getString("ff.icons.persist");
}
}
},
///////////////////////////
// nsISupports
QueryInterface: function Icons_QueryInterface(iid)
{
if (!iid.equals(Components.interfaces.nsIWebProgressListener) &&
!iid.equals(Components.interfaces.nsISupports))
throw Components.results.NS_ERROR_NO_INTERFACE;
return this;
}
};